/**
 * 
 */
package com.sci.web.action.systemmanage;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import com.sci.web.action.util.BaseAction;
import com.sci.web.bean.PersmissionPojo;
import com.sci.web.dao.SystemManageDao;

/**
 * @author  BaiFuyou
 * @date: Nov 17, 2011 11:02:55 AM
 */
public class GetAllPermissionAction extends BaseAction {
	private static final long serialVersionUID = -6969786644244094929L;
	private String name;
	private int id;
	private String start;
	private String limit;
	@Resource
	private SystemManageDao systemManageDao;
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		List<com.sci.web.bean.PersmissionPojo> list = new ArrayList<com.sci.web.bean.PersmissionPojo>();
		if(id == 0 || name.equals("")){
			String str ="{'total':"+list.size()+","+"'list' :"+super.getJSONArrayString(list)+"}";
			super.setContentType(JSON);
			super.outPrint(str);
			return "json";
		}
		int end = Integer.parseInt(this.start)+Integer.parseInt(this.limit);
		list = systemManageDao.getPermissionPojoByRid(id);	
		int length = list.size();
		if(end > length) {
			end = length;
		}
		List<PersmissionPojo> sublist =  list.subList(Integer.parseInt(this.start), end);
		String str ="{'total':"+list.size()+","+"'list' :"+super.getJSONArrayString(sublist)+"}";
		super.setContentType(JSON);
		super.outPrint(str);
//		System.out.println(str);
		return "json";
//		return "json";
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	/**
	 * @return the start
	 */
	public String getStart() {
		return start;
	}
	/**
	 * @param start the start to set
	 */
	public void setStart(String start) {
		this.start = start;
	}
	/**
	 * @return the limit
	 */
	public String getLimit() {
		return limit;
	}
	/**
	 * @param limit the limit to set
	 */
	public void setLimit(String limit) {
		this.limit = limit;
	}
}
